<template>
  <div class="PersonIndexOnSale tPage">
    <ul class="dataList">
      <li v-for="v in dataList">
        <Item02 :pinfo="v">
          <template slot="icons">
            <i class="icon fa fa-cart-plus pull-right"></i>
            <wLikeCount class="icon" :works_id="parseInt(v.works_id)" :pme_is_like="v.me_is_like" :plikecount="parseInt(v.like_count)"></wLikeCount>
          </template>
        </Item02>
      </li>
    </ul>
    <GetMore @getmore="get_worklist" ref="GetMore" :getDataListDoing="getDataListDoing"></GetMore>
  </div>
</template>
<style scoped>
.dataList{}
.dataList>li{box-sizing: border-box;margin-top: .4rem}
.fa-cart-plus{font-size: .48rem}
.icon{margin-left: .4rem}
</style>
<script>
import Item02 from "../../components/work/Item02";
import wLikeCount from "../../components/work/likeCount";
import GetMore from "../../components/buttons/GetMore";
export default {
  name:"OnSale",
  components: {Item02,GetMore,wLikeCount},
  data(){
    return {
      dUserinfo:[],
      dataList:[],
      page:1,
      getDataListDoing:0
    }
  },
  methods:{
    get_worklist(){
      let _this = this
      if (!_this.dUserinfo.uid)return false;
      if (_this.getDataListDoing)return false;
      _this.getDataListDoing=1
      myjs.get_worklist({uid:_this.dUserinfo.uid,page:_this.page,is_on_sale:2},function(data){
        _this.dataList=_this.dataList.concat(data.data)
        _this.page++
        _this.getDataListDoing=0
      },function(){
        _this.$refs.GetMore.setNoMore()
        _this.getDataListDoing=0
      })
    }
  },
  mounted() {
    let _this=this
    setTimeout(function(){
      _this.dUserinfo = _this.$store.getters.getUserinfo
      if (!_this.dUserinfo){
        _this.$router.push({name:"PersonIndex"})
      }
      _this.get_worklist()
    },500)
  },
  created() {
    let _this=this
    _this.$nextTick(function(){
      $(window).scroll(function(){
        if (_this.$route.name!==_this.$options.name)return false
        let scrollTop = $(this).scrollTop();
        let scrollHeight = $(document).height();
        let windowHeight = $(this).height();
        if(scrollHeight - (scrollTop + windowHeight) < 100){
          console.log("you are in the bottom sale");
          _this.get_worklist()
        }
      })
    })
  }
}
</script>
